<template>
  <div class="wrapper">
    <v-head :clientdata="clientData" />
    <v-sidebar />
    <div class="content-box" :class="{'content-collapse':collapse}" style="background-color:#EDF2EE ">
      <div class="content">
        <transition name="move" mode="out-in">
          <keep-alive :include="tagsList">
            <router-view />
          </keep-alive>
        </transition>
        <el-backtop target=".content" />
      </div>
    </div>
  </div>
</template>

<script>
import API from '../../api/index'
import vHead from './Header.vue'
import vSidebar from './Sidebar.vue'
import bus from './bus'
export default {
  components: {
    vHead,
    vSidebar
  },
  data() {
    return {
      tagsList: [],
      collapse: false,
      clientData: []
    }
  },
  created() {
    bus.$on('collapse-content', msg => {
      this.collapse = msg
    })

    // 只有在标签页列表里的页面才使用keep-alive，即关闭标签之后就不保存到内存中了。
    bus.$on('tags', msg => {
      const arr = []
      for (let i = 0, len = msg.length; i < len; i++) {
        msg[i].name && arr.push(msg[i].name)
      }
      this.tagsList = arr
    })
  },
  mounted() {
    this.getInfo()
    this.getClient()
  },
  methods: {
    // 根据登录获取信息
    getInfo() {
      const param = {
        // clientId: JSON.parse(localStorage.getItem('huapuauth')).deptId

        clientId: JSON.parse(localStorage.getItem('huapuauth')).deptId
      }
      this.loading = true
      API.login.InfoFun(param).then((res) => {
        this.loading = false
        // console.log(res)
      }).catch(function(error) {
        console.log(error)
      })
    },
    // 客户列表下拉
    getClient() {
      const that = this
      that.loading = true
      API.login.clientFun().then((res) => {
        if (res.code === 1) {
          that.clientData = res.data
          // console.log(res.data)
        }
        that.loading = false
      }).catch(function(error) {
        console.log(error)
      })
    }
  }
}
</script>
<style>

</style>
